
/*
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-15 19:54:32
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-20 22:40:30
 */
import { userCustomerSubordinateApi } from "@/services/customer"
import type { ICustomerData } from "@/types/customer"
import { ref, onMounted } from "vue"
import type { Ref } from 'vue'
/**
 * 处理dialogVisible
 */
export const userDialogVisible = (visible = false): [Ref<boolean>, (visible: boolean, callback?: () => void) => void] => {
    const data = ref(false)
    const setData = (visible: boolean, callback: () => void = () => { }) => {
        data.value = visible
        callback()
    }
    return [data, setData]
}
//全部顾客列表
export const useCustomerList = (
    pageNum: number = 1,
    query: object = {},
    initialSize: number = 10
): [Ref<ICustomerData.ICustomerList[]>, Ref<number>, (page?: number, size?: number, query?: object) => Promise<void>] => {
    const data = ref<ICustomerData.ICustomerList[]>([]);
    const total = ref(0);

    const loadData = async (page: number = 1, size: number = 10, query: object = {}) => {
        try {
            const ret = await userCustomerSubordinateApi(page, query, size);
            if (ret.code === 200) {
                data.value = ret.data.customer || [];
                total.value = ret.data.total || 0;
            } else {

            }
        } catch (error) {

        }
    };

    onMounted(() => {
        loadData(pageNum, initialSize, query);
    });

    return [data, total, loadData]
};

/**
 * 知识点
 * callback: () => void = () => { } 表示 callback 是一个可选的回调函数参数，并且它的默认值是一个空函数。
 * callback: () => void 表示 callback 是一个函数类型，它不接受任何参数，并且不返回任何值（即 void）。= () => { } 表示如果没有提供 callback 参数的值，默认值就是一个空函数，即一个没有任何操作的函数。
 */